define(['jquery'], function () {
    class Floatbar {
        constructor() {
            this.init().then(() =>{
                this.calcCartCounts()
            })
        }
        init() {
            return new Promise(resolve =>{
                $('.floatbar').load('/html/modules/floatbar.html', resolve)
            })
            
        }
        calcCartCounts(){
            // 取出localStorage,计算总数量
            let totalCount = 0
            let cart = localStorage.getItem('cart')
            if(cart){
                cart = JSON.parse(cart)
                totalCount = cart.reduce((count , shop) => {
                    count += shop.count
                    return count
                }, 0)
            }
            $('#count-num').html(totalCount)
        }
    }
    return new Floatbar()
});